package com.yz.conroller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yz.core.utils.HttpUtils;
import com.yz.core.utils.R;
import com.yz.vo.InvitataionEntity;
import com.yz.vo.InvitataionStatusVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @className: invitationController
 * @author: shuishui
 * @date: 2023/01/11 17:14
 */
@RestController
@RequestMapping("/invitation")
public class invitationController {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${blog.web.base}")
    private String webBaseUrel;
    @Autowired
    private HttpUtils httpUtils;
    @PostMapping("/page")
    public R page(@RequestBody Page<InvitataionEntity> page){
        /*
        * request请求步骤
        * 1：创建headers对象，设置请求类型
        * 2：创建请求实体，将请求头和请求体封装进去
        */
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity httpEntity = new HttpEntity(page,httpHeaders);
        ResponseEntity<Page> ResponseEntity = restTemplate.postForEntity(webBaseUrel + "invitataionController/page", httpEntity, Page.class);
        return R.ok().put("data",ResponseEntity.getBody());
    }
    @PostMapping("/updateType")
    public R updateType(@RequestBody InvitataionStatusVo invitataionStatus) {
        ResponseEntity responseEntity = httpUtils.post(webBaseUrel + "invitataionController/typeChange", invitataionStatus);
        Object body = responseEntity.getBody();
        return R.ok();
    }
    @GetMapping("invitataionInfo/{id}")
    public ResponseEntity InfoById(@PathVariable String id){
        ResponseEntity responseEntity = httpUtils.get(webBaseUrel + "invitataionController/invitataionInfo/" + id);
        return responseEntity;
    }
}
